package com.shaohai.live;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.shaohai.live.adapter.BaseRecyclerAdapter;
import com.shaohai.live.adapter.RecyclerMenuItemAdapter;
import com.shaohai.live.entity.RecyclerMenuItemDescription;
import com.shaohai.live.ui.FSActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HomeActivity extends FSActivity {
    RecyclerMenuItemAdapter itemMenuAdapter;
    @BindView(R.id.recyclerView) RecyclerView recyclerView;
    List<RecyclerMenuItemDescription> menus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.bind(this);
        initializeView();
    }

    @Override
    protected void initializeView() {
        menus = new ArrayList<>();
        menus.add(new RecyclerMenuItemDescription("课程直播", R.mipmap.ic_video, WaitingCourseActivity.class));
        menus.add(new RecyclerMenuItemDescription("直播记录", R.mipmap.ic_record, CourseHistoryActivity.class));
        itemMenuAdapter = new RecyclerMenuItemAdapter(context, menus);
        recyclerView.setAdapter(itemMenuAdapter);
        int spanCount = 3;
        recyclerView.setLayoutManager(new GridLayoutManager(context, spanCount));
        itemMenuAdapter.setOnItemClickListener((itemView, pos) -> {
            RecyclerMenuItemDescription menuItemDescription = menus.get(pos);
            if (menuItemDescription.menuClass != null) {
                Intent intent = new Intent(context, menuItemDescription.menuClass);
                startActivity(intent);
            }
        });
    }

}
